package ldkxingzhe.ldkxingzhedemo.widgets;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import ldkxingzhe.ldkxingzhedemo.R;

/**
 * Created by ke on 15-9-6.
 */
public class ImageViewPager extends PagerAdapter{

    private Context context;

    public ImageViewPager(Context context){
        this.context = context;
    }
    private int[] mImages = new int[]{
            R.drawable.adward_box_1,R.drawable.adward_box_2,R.drawable.adward_box_3,R.drawable.adward_box_4
    };
    @Override
    public int getCount() {
        return mImages.length;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == (ImageView)object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ImageView imageView = new ImageView(context);
        imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        imageView.setImageResource(mImages[position]);
        ((ViewPager)container).addView(imageView,0);
        return imageView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        ((ViewPager)container).removeView((ImageView)object);
    }
}
